import { ref } from 'vue'
import { useIntersectionObserver } from '@vueuse/core'

export const useObserver = (apiFn) => {
  const target = ref(null)
  const { stop } = useIntersectionObserver(
    target, ([{ isIntersecting }]) => {
      // console.log(isIntersecting)
      if (isIntersecting) {
        stop()
        apiFn()
      }
    }
  )
  return { target }
}
